/*
 * Amkai Enterprise Solution (AES.) 
 * Copyright 2004-2011 by Amkai(TM), Inc.
 * www.amkai.com
 * 
 * Project: webservice
 * Package: com.amkai.aes.webservice.binary.objecthandler.preference
 * File: PreferenceJobHandler.java
 * Created: Jul 6, 2011
 * Author: KeriKornel
 * 
 */
package com.amkai.aes.webservice.binary.objecthandler.preference;

import java.io.Serializable;

import com.amkai.aes.aescommon.preference.PreferenceManager;
import com.amkai.aes.aescommon.preference.PreferenceResult;
import com.amkai.aes.aescommon.service.binary.job.preference.PreferenceJob;
import com.amkai.aes.webservice.binary.JobObjectHandler;

/**
 * @author KeriKornel
 *
 */
// KKORNEL: AES-18018
@SuppressWarnings("rawtypes")
public class PreferenceJobHandler implements JobObjectHandler<PreferenceJob, Serializable, PreferenceResult> {

	@Override
	public PreferenceResult process(PreferenceJob job, Serializable object) throws Exception {
		switch (job.getJobKind()) {
			case GET_PREFERENCE: 
				return PreferenceManager.getPreference(job.getPreferenceClass(), job.getDepartmentId());
			case GET_PREFERENCE_FOR_ALL_AVAILABLE_LEVELS: 
				return PreferenceManager.getPreferencesForAllAvailableLevels(job.getPreferenceClass(), job.getDepartmentId());
			case SAVE_PREFERENCES: {
					PreferenceManager.savePreferences(job.getPreferences());
					break;
			}
			case GET_USER_AND_WORKGROUP: 
				return PreferenceManager.getUserAndWorkGroupForPassportAndBE(job.getPassportId(), job.getDepartmentId());
			case GET_PREFERENCE_FOR_ENTERPRISE: 
				return PreferenceManager.getPreferenceForEnterprise(job.getPreferenceClass());
			case GET_PREFERENCE_FOR_BUSINESSGROUP: 
				return PreferenceManager.getPreferenceForBusinessGroup(job.getPreferenceClass(), job.getBusinessGroupId());
			case GET_PREFERENCE_FOR_WORKGROUP: 
				return PreferenceManager.getPreferenceForWorkGroup(job.getPreferenceClass(), job.getWorkGroupId());
			case GET_PREFERENCE_FOR_BUSINESSENTITY: 
				return PreferenceManager.getPreferenceForBusinessEntity(job.getPreferenceClass(), job.getDepartmentId());
			case GET_PREFERENCE_FOR_USERGROUP: 
				return PreferenceManager.getPreferenceForUserGroup(job.getPreferenceClass(), job.getUserGroupId());
			case GET_PREFERENCE_FOR_USER: 
				return PreferenceManager.getPreferenceForUser(job.getPreferenceClass(), job.getDepartmentId(), job.getPassportId());
			case GET_LEVELS_WITH_SAVE_DATA: 
				return PreferenceManager.getPreferenceLevelsWhichHaveSavedData(job.getPreferenceClass(), job.getBusinessGroupId(), job.getWorkGroupId(), job.getDepartmentId(), job.getUserGroupId(), job.getPassportId());
			case RESET_PREFERENCE_FOR_ENTERPRISE: 
				return PreferenceManager.resetPreferenceForEnterprise(job.getPreferenceClass());
			case RESET_PREFERENCE_FOR_BUSINESSGROUP: 
				return PreferenceManager.resetPreferenceForBusinessGroup(job.getPreferenceClass(), job.getBusinessGroupId());
			case RESET_PREFERENCE_FOR_WORKGROUP: 
				return PreferenceManager.resetPreferenceForWorkGroup(job.getPreferenceClass(), job.getWorkGroupId());
			case RESET_PREFERENCE_FOR_BUSINESSENTITY: 
				return PreferenceManager.resetPreferenceForBusinessEntity(job.getPreferenceClass(), job.getDepartmentId());
			case RESET_PREFERENCE_FOR_USERGROUP: 
				return PreferenceManager.resetPreferenceForUserGroup(job.getPreferenceClass(), job.getUserGroupId());
			case RESET_PREFERENCE_FOR_USER: 
				return PreferenceManager.resetPreferenceForUser(job.getPreferenceClass(), job.getDepartmentId(), job.getPassportId());
		}
		return null;
	}

}
